package com.hualan.controller;
import com.hualan.service.UserService;
import com.hualan.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;


    @GetMapping("/login")
    public R login1(String username,String passwd){
        int i = userService.login(username,passwd);

        if(i==1){
            return R.success("");
        }else{
            return R.fail(i);
        }
    }

    @GetMapping("/checkphone")
    public R checkphone(String phone){
        int i = userService.checkphone(phone);
        if(i==1){
            return R.success("");
        }else{
            return R.fail(i);
        }
    }


    @GetMapping("/insertall")
    public R insertall(String username,String passwd,String phone){

        int i = userService.insertall(username,passwd,phone);
        if(i==1){
            return R.success("");
        }else{
            return R.fail(i);
        }
    }


    @GetMapping("/selectphonebyusername")
    public R selectphonebyusername(String username){

        String i = userService.selectphonebyusername(username);
        if(i!=null){
            return R.success(i);
        }else{
            return R.fail(i);
        }
    }
    @GetMapping("/updatepasswdbyusername")
    public R updatepasswdbyusername(String username,String password){
        int i = userService.updatepasswdbyusername(username, password);

        if(i==1){
            return R.success("");
        }else{
            return R.fail(i);
        }
    }
    @GetMapping("/selectUserByName")
    public R selectUserByName(String name){
        return userService.selectUserByName(name);
    }

    @GetMapping("/loginVue")
    public R userLogin(String username, String password){
        int num = userService.findAdUserByUsername(username,password);
        if (num == 0){
            return R.success(num);
        }else if (num == 11){
            return R.success(num);
        }else if (num == 21){
            return R.success(num);
        }else {
            return R.success(num);
        }
    }

}
